package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.MantissaProcessingType;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.EmpSocItemExample.E_AMOUNT_COMPANY_END;
import static org.jsola.hr.example.EmpSocItemExample.E_AMOUNT_COMPANY_START;
import static org.jsola.hr.example.EmpSocItemExample.E_AMOUNT_PERSONAL_END;
import static org.jsola.hr.example.EmpSocItemExample.E_AMOUNT_PERSONAL_START;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_DEFAULT_END;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_DEFAULT_START;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_MAX_END;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_MAX_START;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_MIN_END;
import static org.jsola.hr.example.EmpSocItemExample.E_CARDINALITY_MIN_START;
import static org.jsola.hr.example.EmpSocItemExample.E_EMP_SOC_ID;
import static org.jsola.hr.example.EmpSocItemExample.E_ITEM_NAME;
import static org.jsola.hr.example.EmpSocItemExample.E_ITEM_REMARK;
import static org.jsola.hr.example.EmpSocItemExample.E_ITEM_TYPE;
import static org.jsola.hr.example.EmpSocItemExample.E_MANTISSA_PROC_COMPANY;
import static org.jsola.hr.example.EmpSocItemExample.E_MANTISSA_PROC_PERSONAL;
import static org.jsola.hr.example.EmpSocItemExample.E_PERSENT_COMPANY_END;
import static org.jsola.hr.example.EmpSocItemExample.E_PERSENT_COMPANY_START;
import static org.jsola.hr.example.EmpSocItemExample.E_PERSENT_PERSONAL_END;
import static org.jsola.hr.example.EmpSocItemExample.E_PERSENT_PERSONAL_START;
import static org.jsola.hr.example.EmpSocItemExample.E_SORT;
import static org.jsola.hr.example.EmpSocItemExample.N_AMOUNT_COMPANY_END;
import static org.jsola.hr.example.EmpSocItemExample.N_AMOUNT_COMPANY_START;
import static org.jsola.hr.example.EmpSocItemExample.N_AMOUNT_PERSONAL_END;
import static org.jsola.hr.example.EmpSocItemExample.N_AMOUNT_PERSONAL_START;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_DEFAULT_END;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_DEFAULT_START;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_MAX_END;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_MAX_START;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_MIN_END;
import static org.jsola.hr.example.EmpSocItemExample.N_CARDINALITY_MIN_START;
import static org.jsola.hr.example.EmpSocItemExample.N_EMP_SOC_ID;
import static org.jsola.hr.example.EmpSocItemExample.N_ITEM_NAME;
import static org.jsola.hr.example.EmpSocItemExample.N_ITEM_REMARK;
import static org.jsola.hr.example.EmpSocItemExample.N_ITEM_TYPE;
import static org.jsola.hr.example.EmpSocItemExample.N_MANTISSA_PROC_COMPANY;
import static org.jsola.hr.example.EmpSocItemExample.N_MANTISSA_PROC_PERSONAL;
import static org.jsola.hr.example.EmpSocItemExample.N_PERSENT_COMPANY_END;
import static org.jsola.hr.example.EmpSocItemExample.N_PERSENT_COMPANY_START;
import static org.jsola.hr.example.EmpSocItemExample.N_PERSENT_PERSONAL_END;
import static org.jsola.hr.example.EmpSocItemExample.N_PERSENT_PERSONAL_START;
import static org.jsola.hr.example.EmpSocItemExample.N_SORT;

/**
 * 员工参保信息表子项
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpSocItemQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_EMP_SOC_ID, example = E_EMP_SOC_ID)
    @Length(max = 32)
    private String empSocId;

    @ApiParam(value = N_ITEM_TYPE, example = E_ITEM_TYPE)
    private Integer itemType;

    @ApiParam(value = N_ITEM_NAME, example = E_ITEM_NAME)
    @Length(max = 255)
    private String itemName;

    /**
     * 默认基数查询范围
     */
    @ApiParam(value = N_CARDINALITY_DEFAULT_START, example = E_CARDINALITY_DEFAULT_START)
    private BigDecimal cardinalityDefaultStart;
    @ApiParam(value = N_CARDINALITY_DEFAULT_END, example = E_CARDINALITY_DEFAULT_END)
    private BigDecimal cardinalityDefaultEnd;


    /**
     * 可选基数最小值查询范围
     */
    @ApiParam(value = N_CARDINALITY_MIN_START, example = E_CARDINALITY_MIN_START)
    private BigDecimal cardinalityMinStart;
    @ApiParam(value = N_CARDINALITY_MIN_END, example = E_CARDINALITY_MIN_END)
    private BigDecimal cardinalityMinEnd;


    /**
     * 可选基数最大值查询范围
     */
    @ApiParam(value = N_CARDINALITY_MAX_START, example = E_CARDINALITY_MAX_START)
    private BigDecimal cardinalityMaxStart;
    @ApiParam(value = N_CARDINALITY_MAX_END, example = E_CARDINALITY_MAX_END)
    private BigDecimal cardinalityMaxEnd;


    /**
     * 公司缴纳比例查询范围
     */
    @ApiParam(value = N_PERSENT_COMPANY_START, example = E_PERSENT_COMPANY_START)
    private BigDecimal persentCompanyStart;
    @ApiParam(value = N_PERSENT_COMPANY_END, example = E_PERSENT_COMPANY_END)
    private BigDecimal persentCompanyEnd;


    /**
     * 个人缴纳比例查询范围
     */
    @ApiParam(value = N_PERSENT_PERSONAL_START, example = E_PERSENT_PERSONAL_START)
    private BigDecimal persentPersonalStart;
    @ApiParam(value = N_PERSENT_PERSONAL_END, example = E_PERSENT_PERSONAL_END)
    private BigDecimal persentPersonalEnd;


    /**
     * 公司金额查询范围
     */
    @ApiParam(value = N_AMOUNT_COMPANY_START, example = E_AMOUNT_COMPANY_START)
    private BigDecimal amountCompanyStart;
    @ApiParam(value = N_AMOUNT_COMPANY_END, example = E_AMOUNT_COMPANY_END)
    private BigDecimal amountCompanyEnd;


    /**
     * 个人金额查询范围
     */
    @ApiParam(value = N_AMOUNT_PERSONAL_START, example = E_AMOUNT_PERSONAL_START)
    private BigDecimal amountPersonalStart;
    @ApiParam(value = N_AMOUNT_PERSONAL_END, example = E_AMOUNT_PERSONAL_END)
    private BigDecimal amountPersonalEnd;


    @ApiParam(value = N_MANTISSA_PROC_COMPANY, example = E_MANTISSA_PROC_COMPANY, allowableValues = MantissaProcessingType.VALUES_STR)
    private Integer mantissaProcCompany;

    @ApiParam(value = N_MANTISSA_PROC_PERSONAL, example = E_MANTISSA_PROC_PERSONAL, allowableValues = MantissaProcessingType.VALUES_STR)
    private Integer mantissaProcPersonal;

    @ApiParam(value = N_SORT, example = E_SORT)
    private Integer sort;

    @ApiParam(value = N_ITEM_REMARK, example = E_ITEM_REMARK)
    @Length(max = 255)
    private String itemRemark;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpSocItemQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

